package com.mall.admin.controller;

import cn.hutool.core.convert.Convert;
import com.mall.admin.service.UmsResourceService;
import com.mall.commons.utils.R;
import com.mall.domain.UmsResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/resource")
public class UmsResourceController {
    @Autowired
    private UmsResourceService umsResourceService;

    @PostMapping("/create")
    public R create(@RequestBody UmsResource umsResource) {
        return umsResourceService.create(umsResource);
    }
    @PostMapping("/delete/{id}")
    public R delete(@PathVariable Integer id){
        return umsResourceService.delete(id);
    }
    @GetMapping("list")
    public R list(Integer categoryId,String  nameKeyword,Integer pageNum,Integer pageSize,String urlKeyword ){
      return umsResourceService.list(categoryId,nameKeyword,pageNum,pageSize,urlKeyword);
    }
    @GetMapping("listAll")
    public R listAll(){
        return umsResourceService.listAll();
    }
    @PostMapping("/update/{id}")
    public R update(@PathVariable Integer id,@RequestBody UmsResource umsResource){
        umsResource.setId(Convert.toLong(id));
        return umsResourceService.update(umsResource);
    }
    @GetMapping("/{id}")
    public R get(@PathVariable Integer id){
        return umsResourceService.get(id);
    }
}
